<template>
  <div class="legalAid">
    <div class="legalAid_list">
      <div
        @click="onItem(item.id)"
        class="legalAid_item"
        v-for="(item , index) in info_list"
        :key="index"
        v-flex_for="{count:info_list.length,number:number,key:index}"
      >
        <div class="imgBox" :style="{backgroundImage:'url('+ item.image_input + ')'}"></div>
        <!-- <img class="item_tu" :src="item.image_input" alt /> -->
        <div class="content">
          <div class="item_title">{{item.title}}</div>
          <p>{{item.synopsis}}</p>
          <div class="time">
            <img src="@/assets/images/news_time.png" alt />
            <!-- <span>{{item.add_time}}</span> -->
          </div>
        </div>
      </div>
    </div>
    <el-pagination
      :page-size="10"
      :total="total"
      background
      layout="prev, pager, next"
      @current-change="changePage"
    ></el-pagination>
  </div>
</template>
<script>
import {
  activity_cate,
  activity_list,
  activity_recruit_add,
} from "@/api/activity.js";
export default {
  data() {
    return {
      info_list: [],
      number: 4,
      total: 1,
      cate_id: "",
    };
  },
  watch: {
    "$store.state.headTitle.activityCurrentCHS": {
      deep: true,
      handler: function (newValue, oldValue) {
        this.cate_id = newValue;
        this.getList(newValue, 1);
      },
    },
  },
  mounted() {
    if (this.$store.state.headTitle.activityCurrentCHS) {
      this.getList(this.$store.state.headTitle.activityCurrentCHS);
    }
    // this.getActivity_cate();
  },
  methods: {
    //活动分类 列表
    getActivity_cate() {
      activity_cate().then((res) => {
        this.cate_list = res.data.data;
        if (this.$route.query.id) {
          this.getList(this.$route.query.id, 1);
          this.navActive = this.cate_list.findIndex(
            (item) => item.id == this.$route.query.id
          );
        } else {
          this.getList(this.cate_list[0].id, 1);
          this.currentId = this.cate_list[0].id;
          this.queryId == this.cate_list[0].id;
          this.navActive = 0;
        }
      });
    },

    //点击单项数据
    onItem(id) {
      this.$router.replace({
        name: "zh_activity_legalAidDetalis",
        query: { id: id, cate_id: this.$route.query.id || this.cate_id },
      });
    },

    //点击分页
    changePage(page) {
      this.getList(this.cate_id, page);
    },

    // 获取列表数据
    getList(cid, page) {
      activity_list({ cid: cid, page: page || 1, limit: 10 }).then((res) => {
        this.info_list = res.data.data;
        this.total = res.data.count;
        if (res.data.data.length < 1) {
          return this.$message({
            message: "暂时没有更多数据了",
            type: "error",
          });
        }
      });
    },
  },
};
</script>
<style scoped src="./sass/activity.css"></style>